import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    component: resolve => require(['../views/Login.vue'], resolve),
    meta: { title: '登录' },
  },
  {
    path: '/home',
    component: resolve => require(['../views/Home.vue'], resolve),
    meta: { title: '主页' },
    redirect:'/home/EmpManage',
    children: [
      {
        path:'EmpManage',
        name:'EM',
        component:resolve => require(['../views/manageviews/EmpManage.vue'], resolve)
      },
      {
        path:'CustManage',
        name:'CustM',
        component:resolve => require(['../views/manageviews/CustManage.vue'], resolve)
      },
      {
        path:'SupplierManage',
        name:'SuppM',
        component:resolve => require(['../views/manageviews/SupplierManage.vue'], resolve)
      },
      {
        path:'PurchaseManage',
        name:'PurchM',
        component:resolve => require(['../views/manageviews/PurchaseManage.vue'], resolve)
      },
      {
        path:'CheckfreightManage',
        name:'CheckM',
        component:resolve => require(['../views/manageviews/CheckfreightManage.vue'], resolve)
      },
      {
        path:'StoreinManage',
        name:'StoreinM',
        component:resolve => require(['../views/manageviews/StoreinManage.vue'], resolve)
      },
      {
        path:'KesuManage',
        name:'KesuM',
        component:resolve => require(['../views/manageviews/KesuManage.vue'], resolve)
      },
      {
        path:'SellManage',
        name:'SellM',
        component:resolve => require(['../views/manageviews/SellManage.vue'], resolve)
      },
      {
        path:'StoreoutManage',
        name:'StoreoutM',
        component:resolve => require(['../views/manageviews/StoreoutManage.vue'], resolve)
      },
      {
        path:'ProductManage',
        name:'ProductM',
        component:resolve => require(['../views/manageviews/ProductManage.vue'], resolve)
      },
      {
        path:'InventoryManage',
        name:'InventoryM',
        component:resolve => require(['../views/manageviews/InventoryManage.vue'], resolve)
      },
    ]
  }
]

const router = new VueRouter({
  //mode: 'history',
  base: process.env.BASE_URL,
  routes
})

/*导航守卫*/
// router.beforeEach((to, from, next) => {
//   if (to.path === '/login') {
//     return next();
//   }
//   const tokenStr = window.sessionStorage.getItem('token')
//   if (tokenStr === null) {
//     next('/login')
//   } else {
//     next()
//   }
// })

export default router
